package work4.work3;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.zip.GZIPInputStream;

public class GetInf {
   public static String  get(String url){
       StringBuilder txt=new StringBuilder();
       //https://devapi.qweather.com/v7/weather/now?location=101010100&key=bf60e343ed1b4cf6b227a76f8b23d81e
       try {
           URL FileUrl=new URL(url);
           HttpURLConnection connection =(HttpURLConnection) FileUrl.openConnection();
           connection.setConnectTimeout(1*1000);

           BufferedReader inputReader = new BufferedReader(
                   new InputStreamReader(new GZIPInputStream(connection.getInputStream()), "UTF-8")
           );
           String line;
           while ((line = inputReader.readLine()) != null) {
               txt.append(line);
           }
           // 关闭输入流
           inputReader.close();
       }
       catch (MalformedURLException ex) {
           throw new RuntimeException(ex);
       } catch (IOException ex) {
           throw new RuntimeException(ex);
       }
       return txt.toString();
   }

}
